package spring.yongongsystem.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import spring.yongongsystem.POJO.dto.OrderDTO;
import spring.yongongsystem.POJO.dto.OrderPageQueryDTO;
import spring.yongongsystem.POJO.entity.Admin;
import spring.yongongsystem.POJO.entity.Order;
import spring.yongongsystem.mapper.OrderMapper;
import spring.yongongsystem.result.PageResult;
import spring.yongongsystem.service.OrderService;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    @Override
    public PageResult pageQuery(OrderPageQueryDTO orderPageQueryDTO) {
        PageHelper.startPage(orderPageQueryDTO.getPage(), orderPageQueryDTO.getPageSize());

        Page<OrderDTO> page = orderMapper.pageQuery(orderPageQueryDTO);
        long total = orderMapper.count();
        List<OrderDTO> records = page.getResult();

        return new PageResult(total, records);
    }

    @Override
    public void save(Order order) {
        order.setOrderStatus("未接受");
        orderMapper.insert(order);
    }

    @Override
    public void deleteById(Long id) {
        orderMapper.deleteById(id);
    }
}
